package com.letv.whatslive.model.dto;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.Activity;
import com.letv.whatslive.model.User;
import com.letv.whatslive.model.constant.ActivityConstants;
import com.letv.whatslive.model.convert.UserConvert;
import lombok.Getter;
import lombok.Setter;

/**
 * Created by gaoshan on 15-9-24.
 */
@Getter
@Setter
public class ActivityDTO {

    private Long id;
    private String title;
    private String tag;
    private String picture;
    private String url;
    private Integer status;
    private Long priority;
    private Long createTime;
    private String aDesc; //活动描述
    private Integer type;  // 1:视频列表 2：h5页面
    private Integer isRecommend; //是否推荐，0:表示不推荐，1表示推荐
    private Long watchNum;
    private String copyWriter; //分享文案
    private Long uid; //活动所属用户Id
    private UserDTO user; // 活动所属用
    private String iconUrl; //活动图标
    private String adUrl; // 活动广告url
    private String gifPicture; //动图封面
    private Integer allowParti; //允许参与
    private String applicationFormUrl;//报名表地址

    public ActivityDTO(Activity activity, String type) {

        // type: 1 首页推荐用
        if ("1".equals(type)) {

            this.setId(ObjectUtils.toLong(activity.getId(), 0L));
            this.setTitle(ObjectUtils.toString(activity.getTitle(), ""));
            this.setTag(ObjectUtils.toString(activity.getTag(), ""));
            this.setPicture(ObjectUtils.toString(activity.getPicture(), ""));
            this.setType(ObjectUtils.toInteger(activity.getType(), 0));
            this.setCopyWriter(ObjectUtils.toString(activity.getCopyWriter(), ""));
            Long watchNum = activity.getWatchNum();
            Long realWatchNum = activity.getRealWatchNum();
            this.setWatchNum(watchNum + realWatchNum);
        } else if ("2".equals(type) || "3".equals(type)) {

            // type: 2 活动列表, 3 活动详情
            this.setId(ObjectUtils.toLong(activity.getId(), 0L));
            this.setTitle(ObjectUtils.toString(activity.getTitle(), ""));
            this.setTag(ObjectUtils.toString(activity.getTag(), ""));
            this.setPicture(ObjectUtils.toString(activity.getPicture(), ""));
            // TODO v2.2.1
            this.setUrl(ActivityConstants.ACTIVITY_SHARE_URL + activity.getId());
            this.setStatus(ObjectUtils.toInteger(activity.getStatus(), 0));
            this.setPriority(ObjectUtils.toLong(activity.getPriority(), 0L));
            this.setCreateTime(ObjectUtils.toLong(activity.getCreateTime(), 0L));
            this.setADesc(ObjectUtils.toString(activity.getADesc(), ""));
            this.setType(ObjectUtils.toInteger(activity.getType(), 0));
            this.setIsRecommend(ObjectUtils.toInteger(activity.getIsRecommend(), 0));
            this.setCopyWriter(ObjectUtils.toString(activity.getCopyWriter(), ""));
            this.setUid(ObjectUtils.toLong(activity.getUid(), 0L));
            this.setIconUrl(ObjectUtils.toString(activity.getIconUrl(), ""));
            this.setAdUrl(ObjectUtils.toString(activity.getAdUrl()));

            if (activity.getUserRef() != null) {

                User user = UserConvert.castDBObjectToUser(activity.getUserRef().fetch());
                if (user != null) {
                    UserDTO dto = new UserDTO(user);
                    this.setUser(dto);
                }
            }

            Long watchNum = activity.getWatchNum();
            Long realWatchNum = activity.getRealWatchNum();
            this.setWatchNum(watchNum + realWatchNum);
        }
        this.setGifPicture(activity.getGifPicture());
        this.setAllowParti(ObjectUtils.toInteger(activity.getAllowParti(), 1));
        this.setApplicationFormUrl(ObjectUtils.toString(activity.getApplicationFormUrl(), ""));
    }

    public ActivityDTO() {

    }

}
